home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / xstats-reporter < prev   
Encoding:
Internet Message Format  |  1996-10-25  |  6.4 KB

  1. Received: by gw.home.vix.com id AA09211; Mon, 12 Dec 94 06:12:15 -0800
  2. Received: by gw.home.vix.com id AA09207; Mon, 12 Dec 94 06:12:12 -0800
  3. Received: from sagres.inria.fr (sagres.inria.fr [128.93.2.26]) by concorde.inria.fr (8.6.9/8.6.9) with ESMTP id PAA25939 for <bind-workers@vix.com>; Mon, 12 Dec 1994 15:12:02 +0100
  4. Received: (from grange@localhost) by sagres.inria.fr (8.6.8/8.6.6) id PAA26305; Mon, 12 Dec 1994 15:12:21 +0100
  5. Date: Mon, 12 Dec 1994 15:12:21 +0100
  6. From: Benoit Grange <grange@sagres.inria.fr>
  7. Message-Id: <199412121412.PAA26305@sagres.inria.fr>
  8. To: bind-workers@vix.com
  9. Subject: Perl script to make graphs from XSTATS
  10.  
  11.  
  12. Here is a draft of a script that produces stats from named XSTATS output.
  13.  
  14. Name this script as you like.
  15. Call it like this:
  16.  
  17. $ procstats -m 86400 -d 86400 XSTATS RQ RQ reboot < stats
  18.  
  19. Where stats is a file containing syslog output from named.
  20.  
  21. It produces stats from the RQ variable of XSTATS lines from the stats.
  22. It writes the stats to a file named RQ (the second RQ of the command
  23. line), and also writes reboot times in the file reboot.
  24.  
  25. With the options above, time origin (value 0) is midnight GMT. You can
  26. add a '-o nnnn' where nnnn is the number of seconds offset from GMT.
  27.  
  28. Using gnuplot, you can type:
  29.  
  30. gnuplot> plot 'RQ' with lines, 'reboot'
  31.  
  32. to show the graph.
  33.  
  34. PS: I am not very proud of the writing style of this piece of code.
  35.  
  36. ------------------------------------------------------------
  37. #!/usr/local/bin/perl
  38.  
  39. ##############################################################################
  40. #                                                                            #
  41. # This script read syslog output of named with option XSTATS                 #
  42. #                                                                            #
  43. # It produces time/value pairs that can be used to draw graphs               #
  44. #                                                                            #
  45. # Benoit Grange, December 1994                                               #
  46. #                                                                            #
  47. ##############################################################################
  48.  
  49. # USAGE: procstats type label ouput-file opt-reboot-output-file
  50.  
  51. # The type currently can be USAGE, NSTATS, XSTATS
  52. # The label is one of the labels in syslog output
  53. # that appears like label=value for the type specified
  54.  
  55. # The output file will contain time value pairs
  56. # The reboot ouput file contain lines specifiing
  57. # when the name server has been rebooted
  58.  
  59. # OPTIONS (all times in seconds)
  60. # -v        verbose
  61. # -s        samples will be written every step
  62. # -b        when do we start, default=first sample
  63. # -e        when do we stop, default=last sample
  64. # -o        offset of samples from start
  65. # -m        make offset modulo this
  66. # -a        add this value to times in output
  67.  
  68. # EXAMPLE
  69. # procstats -s 900 -a 1 XSTATS RQ RQ reboot
  70. #                        |     |   | 
  71. #                      type  value output file
  72.  
  73. $debug = 0;
  74.  
  75. $step = 3600;
  76. $tstart = 0;
  77. $tstop = 1e10;
  78. $tdiv = 1;
  79. $toffset = 0;
  80. $tmodulo = 0;
  81. $tadd = 0;
  82.  
  83. $telapsed = 0;
  84. $vtotal = 0;
  85.  
  86. require "getopts.pl";
  87.  
  88. exit if !&Getopts('vs:b:e:o:m:d:a:');
  89.  
  90. print "OPT_S $opt_s\n" if defined($opt_s);
  91.  
  92. $debug++ if defined($opt_v);
  93. $step = $opt_s if defined($opt_s);
  94. $tstart = $opt_b if defined($opt_b);
  95. $tstop = $opt_e if defined($opt_e);
  96. $toffset = $opt_o if defined($opt_o);
  97. $tmodulo = $opt_m if defined($opt_m);
  98. $tdiv = $opt_d if defined($opt_d);
  99. $tadd = $opt_a if defined($opt_a);
  100.  
  101. if (($#ARGV - $[) < 2) {
  102.     print STDERR "Usage: [options] TYPE LABEL OUTPUT [reboot-output]\n";
  103.     exit 1;
  104. }
  105.  
  106. $qtype=$ARGV[0];
  107. $qname=$ARGV[1];
  108.  
  109. if ($ARGV[2]) {
  110.     $qout =$ARGV[2];
  111.     (open(OUT, ">".$qout)) || die "Can't open $qout";
  112. }
  113.  
  114. if ($ARGV[3]) {
  115.     (open(OUTBOOT, ">".$ARGV[3])) || die "Can't open $ARGV[3]";
  116. } else {
  117.     open(OUTBOOT, ">/dev/null");
  118. }
  119.  
  120. $tprev = 0;
  121. $tnext = 0;
  122. $tboot = 0;
  123.  
  124. printf STDERR "Start\t%09d\n", $tstart;
  125. printf STDERR "Step\t%09d\n", $step;
  126. printf STDERR "Offset\t%09d\n", $toffset;
  127. printf STDERR "Div\t%09d\n", $tdiv;
  128. printf STDERR "Add\t%g\n", $tadd;
  129.  
  130. # Read lines, produces output
  131. loop:
  132.  
  133. for($t=$tstart; $t < $tstop; $t += $step) {
  134.     # Check if $tprev <= $t <= $tnext
  135.     while (($tnext < $t) || ($tprev == 0)) {
  136.     $tprev = $tnext;
  137.     $vprev = $vnext;
  138.     last loop if (&readnext() == 0);
  139.     if ($tstart == 0) {
  140.         $t = $tstart = $time;
  141.         $toffset = $tstart if ($toffset == 0);
  142.         $toffset = $toffset - $toffset % $tmodulo if $tmodulo > 0;
  143.         printf STDERR "Start\t%09d\n", $tstart;
  144.     }
  145.     $tnext = $time;
  146.     $vnext = $value;
  147.     if ($tboot != $boot) {    # Rebooted, get next point
  148.         # Finish previous line
  149.         printf OUT "%g %g\n", ($tprev-$toffset) / $tdiv + $tadd, ($vprev - $pinter)/($tprev - $tpinter)
  150.         if (($tpinter > 0) && ($tprev > $tpinter));
  151.         # Skip a line
  152.         printf OUT "\n";
  153.         printf STDERR "\t\tReboot at %d\n", $t;
  154.         # Update vars
  155.         $tboot = $boot;
  156.         $pinter  = $value;
  157.         $tpinter = $time;
  158.         $vtotal += $vprev if ($tprev > $tstart);
  159.         # Update totals
  160.         if (($tprev > 0) && ($t > $tstart)) {
  161.         printf STDERR "\t\tMissing %d seconds\n", $time - $tprev;
  162.         $tmissing += $time - $tprev ;
  163.         }
  164.         # Add a line to reboot file
  165.         printf OUTBOOT "%g 0\n", ($time-$toffset)/$tdiv+$tadd;
  166.         # Continue from NOW on
  167.         $t = $tnext;
  168.     }
  169.     }
  170.     # We have prev and next values
  171.     if ($tnext == $t) {
  172.     $vinter = $vnext;
  173.     } else {
  174.     printf STDERR "t=%8d prev=%8d next=%8d values prev=%8d next=%8d\n",
  175.     $t, $tprev, $tnext, $vprev, $vnext if ($debug);
  176.     $vinter = $vprev +
  177.         (($vnext-$vprev)/($tnext-$tprev)) * ($t - $tprev);
  178.     }
  179.     printf STDERR "t=%08d value=%08d prev value=%08d time=%08d\n",
  180.     $t, $vinter, $pinter, $tpinter if ($debug);
  181.     
  182.     if ($t > $tpinter) {
  183.     printf OUT "%g %g\n", ($t-$toffset) / $tdiv + $tadd, ($vinter - $pinter)/($t - $tpinter);
  184.     }
  185.  
  186.     $pinter = $vinter;
  187.     $tpinter = $t;
  188. }
  189.  
  190. $vtotal += $value;
  191.  
  192. printf STDERR "End\t%09d\n", $t;
  193. printf STDERR "Elapsed\t%09d\n", $t - $tstart;
  194. printf STDERR "Missing\t%09d\n", $tmissing;
  195. printf STDERR "Total\t%09d\n", $vtotal;
  196.  
  197. # Stats don't work
  198. #if ($t > $tstart) {
  199. #    printf STDERR "Avg\t%g\n", $vtotal/(($t-$tstart)-$tmissing);
  200. #}
  201.  
  202. sub readnext
  203. {
  204.     do {
  205.     return 0 if (!($_ = <STDIN>));
  206.     } until (/$qtype (\d+) (\d+).*\s$qname=([.\de+]+)/);
  207.     $time = $1;
  208.     $boot = $2;
  209.     $value = $3;
  210.     print STDERR "TIME=$time BOOT=$boot VALUE=$value\n" if ($debug);
  211.     return 1;
  212. }
  213.  
  214. __END__
  215. ---------------
  216. Benoit Grange
  217. NIC France
  218.  
  219. E-Mail: Benoit.Grange@inria.fr
  220.